<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="${ctx}/static/lib/layui/css/layui.css">
<style type="text/css">
	.main_div{
		margin : 15px;
	}
</style>
</head>
<body>
  	<div class="main_div">
		<form id="from_update" class="layui-form layui-form-pane" action="">
		<input type="hidden" id="id" name="id"/>
		  <div class="layui-form-item">
		    <label class="layui-form-label">用户名</label>
		    <div class="layui-input-block">
		      <input type="text" name="name" id="name" autocomplete="off"  class="layui-input">
		    </div>
		  </div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">密码</label>
		    <div class="layui-input-block">
		      <input type="text" name="password" id="password" lay-verify="required"  autocomplete="off" class="layui-input">
		    </div>
		  </div>
		  
		  <div class="layui-form-item">
		    <label class="layui-form-label">真实姓名</label>
		    <div class="layui-input-inline">
		      <input type="text" name="trueName" id="trueName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
		    </div>
		  </div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">邮件</label>
		    <div class="layui-input-inline">
		      <input type="text" name="email" id="email" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
		    </div>
		  </div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">联系电话</label>
		    <div class="layui-input-inline">
		      <input type="text" name="phone" id="phone" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
		    </div>
		  </div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">角色</label>
		   <div class="layui-input-block" id="roles" name="roles">
		    </div>
		  </div>
		</form>
		<input type="button" class="layui-btn" onclick="submitForm()" value="修改">
	</div>


	<script src="${ctx}/static/back/js/jquery.js"></script>
	<script src="${ctx}/static/commom/mylayer.js"></script>
	<script src="${ctx}/static/commom/util.js"></script>
	<script src="${ctx}/static/lib/layui/layui.js"></script>
	<script src="${ctx}/static/lib/kindeditor/kindeditor.js"></script>
	<script src="${ctx}/static/lib/kindeditor/lang/zh_CN.js"></script>
	<script>
 	layui.config({
	    base : '${ctx}/static/lib/'
	  }).extend({
	    selectM: './layui_extends/selectM'
	  }).use(['form','upload','selectM'],function(){
	  	var form = layui.form;
	  	var upload = layui.upload;
	  	var selectM = layui.selectM;
	  	
		  //监听select选择
		  //下拉选择框被选中时触发，回调函x数返回一个object参数，携带两个成员：
			console.log("${param.userId}");
	  	$.ajax({
			url : '${ctx}/user/selectRolesandUsers.action',
			type : 'POST',
			data : {"userId" : "${param.userId}"},
			dataType : 'json',
			success : function(resp) {
				if(resp.code == util.SUCCESS) {
					mylayer.success(resp.msg);
					var LayuiMvo = resp.data["LayuiMvo"];
					var values = resp.data["values"];
					var user = resp.data["user"];
					$("#id").val(user.id);
					$("#name").val(user.name);
					$("#password").val(user.password)
					$("#trueName").val(user.trueName)
					$("#email").val(user.email)
					$("#phone").val(user.phone)
					
					 //多选标签-基本配置
				    var tagIns = selectM({
				      //元素容器【必填】
				      elem: '#roles'
				      //候选数据【必填】
				      ,data: LayuiMvo
				      //默认值
				      ,selected: values
				      // 默认最多选中5个
				      ,max : 100
				    });
				} else {
					mylayer.errorMsg(resp.msg);
				}
			}
		});
	  });
		
		//ajax方式提交form表单
		function submitForm(){
			$.ajax({
				url : '${ctx}/user/update.action',
				data : $('#from_update').serialize(),
				type : 'POST',
				dataType : 'json',
				success : function(resp) {
					if(resp.code == util.SUCCESS) {
						mylayer.success(resp.msg);
						var index = parent.layer.getFrameIndex(window.name);
			               setTimeout(function() {
			                  parent.layer.close(index);
			                  //刷新父页面
			                  window.parent.location.reload();
			               }, 1000);
					} else {
						mylayer.errorMsg(resp.msg);
					}
				}
			});
		}
		
		var myKindEditor ;
        KindEditor.ready(function(K) {
            var kingEditorParams = {
                 //指定上传文件参数名称
                 filePostName  : "file",
                 //指定上传文件请求的url。
                 uploadJson : '${ctx}/upload/uploadImgByEditor.action',
                 //上传类型，分别为image、flash、media、file
                 dir : "image",
                 afterBlur: function () { this.sync(); }
           }
           var editor = K.editor(kingEditorParams);
           
          //富文本编辑器
          myKindEditor = KindEditor.create('#from_update[name=detail]', kingEditorParams);
        });
	  
	</script>
</body>
</html>
